using UnityEngine;

public class FloatingPlayerName : MonoBehaviour
{
	public static FloatingPlayerName instance;

	public GameObject _target;

	public Camera worldCamera;

	public Camera guiCamera;

	public bool isFloating = true;

	private UILabel _lableName;

	[SerializeField]
	private UILabel _lableLevel;

	private Vector3 _pos;

	private void Awake()
	{
		instance = this;
		_lableName = GetComponent<UILabel>();
		if (_lableLevel == null)
		{
			Transform transform = base.transform.FindChild("lb_Level");
			if (transform != null)
			{
				_lableLevel = transform.GetComponent<UILabel>();
			}
		}
		guiCamera = NGUITools.FindCameraForLayer(8);
	}

	private void Update()
	{
		if (CarInShopManager.instance != null && _lableName != null)
		{
			if (CarInShopManager.instance.active && _lableName.enabled)
			{
				_lableName.enabled = false;
				_lableLevel.enabled = false;
			}
			else if (!CarInShopManager.instance.active && !_lableName.enabled)
			{
				_lableName.enabled = true;
				_lableLevel.enabled = true;
			}
		}
		UpdateFloatingText();
	}

	private void OnEnable()
	{
		UpdateFloatingText();
	}

	public void LateUpdate()
	{
		if (_target != null && isFloating)
		{
			_lableName.enabled = true;
			_pos = worldCamera.WorldToViewportPoint(_target.transform.position);
			_pos = guiCamera.ViewportToWorldPoint(_pos);
			_pos.z = 0f;
			base.transform.position = _pos;
		}
	}

	public void UpdateFloatingText()
	{
		if (_lableName != null)
		{
			_lableName.text = settings.tekName;
		}
		if (_lableLevel != null)
		{
			_lableLevel.text = "1";
		}
	}

	public void DynamicNameChange(string name)
	{
		_lableName.text = name;
	}

	public void ActivateLevelLable()
	{
		_lableLevel.gameObject.SetActive(true);
	}

	public void DeactivateLevelLable()
	{
		_lableLevel.gameObject.SetActive(false);
	}
}
